import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:psi/pages/home/me/me_view.dart';
import 'package:psi/pages/home/purchase/purchase_view.dart';
import 'package:psi/pages/home/sales/sales_view.dart';
import 'package:psi/services/user_logic.dart';
import 'package:psi/utils/widget_util.dart';

import '../../generated/assets.dart';
import '../../services/user_logic.dart';
import '../../widgets/keep_alive_wrapper.dart';
import '../../widgets/shake_tab_button.dart';
import 'home_logic.dart';

class HomePage extends StatelessWidget {
  final logic = Get.find<HomeLogic>();
  final state = Get.find<HomeLogic>().state;


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: PageView(
          physics: const NeverScrollableScrollPhysics(),
          controller: state.pageController,
          children: [
            KeepAliveWrapper(child: PurchasePage()),
            KeepAliveWrapper(child: SalesPage()),
            KeepAliveWrapper(child: MePage())
          ],
        ),
      ),
      bottomNavigationBar: WidgetUtil.getCardItem(
        color: Colors.white,
        padding: EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight, top: 8),
        radius: BorderRadius.vertical(top: Radius.circular(32)),
        child: Container(
          alignment: Alignment.center,
          height: 64,
          child: Obx(() {
              return Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  ShakeTabButton(
                    imageName: R.tabPurchase,
                    title: '采购',
                    isSelected: state.currentIndex.value == 0,
                    onPressed: () {
                      if (state.currentIndex.value != 0) {
                        state.currentIndex.value = 0;
                        state.pageController.jumpToPage(0);
                      }
                    },
                  ),
                  ShakeTabButton(
                    imageName: R.tabSales,
                    title: '销售',
                    isSelected: state.currentIndex.value == 1,
                    onPressed: () {
                      if (state.currentIndex.value != 1) {
                        state.currentIndex.value = 1;
                        state.pageController.jumpToPage(1);
                      }
                    },
                  ),
                  ShakeTabButton(
                    imageName: R.tabMe,
                    title: '我的',
                    isSelected: state.currentIndex.value == 2,
                    onPressed: () {
                      if (state.currentIndex.value != 2) {
                        state.currentIndex.value = 2;
                        state.pageController.jumpToPage(2);
                      }
                    },
                  ),
                ],
              );
            }),
          ),
      ),
    );
  }
}
